package com.bsoft.controller.Topic;

import com.bsoft.Producer.Topic.Demo02Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

@Slf4j
@RestController
public class ProductTopicController {
    @Autowired
    private Demo02Producer demo02Producer;

    @GetMapping("/testSyncSendSuccess")
    public void testSyncSendSuccess() throws InterruptedException {
        int id = (int) (System.currentTimeMillis() / 1000);
        demo02Producer.syncSend(id, "da.yu.nai");
        log.info("[testSyncSend][发送编号：[{}] 发送成功]", id);
        //阻塞等待
        new CountDownLatch(1).await();
    }

    @GetMapping("/testSyncSendFailure")
    public void testSyncSendFailure() throws InterruptedException {
        int id = (int) (System.currentTimeMillis() / 1000);
        demo02Producer.syncSend(id, "yu.nai.shuai");
        log.info("testSyncSend][发送编号：[{}] 发送成功]\"", id);
        //阻塞等待 保证消费
        new CountDownLatch(1).await();
    }
}
